package util

import (
	"fmt"
	"math/rand"
	"strconv"
	"strings"

	"github.com/google/uuid"
)

// StringRandom 生成指定位数的字符
func StringRandom(width int) string {
	// var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
	// b := make([]rune, width)
	// for i := range b {
	// 	b[i] = letterRunes[rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(letterRunes))]
	// }
	// return string(b)
	randBytes := make([]byte, width/2)
	rand.Read(randBytes)
	return fmt.Sprintf("%x", randBytes)

}

func StringSplit(s, sp string) (v []int) {
	strv := strings.Split(s, sp)
	for _, s1 := range strv {
		if s1 == "" {
			continue
		}
		n, _ := strconv.Atoi(s1)
		v = append(v, n)
	}
	return
}

// UUID 生成Guid字串
func UUID() string {
	return uuid.New().String()
}
